package seismosurfer.database;

import java.sql.Timestamp;

import seismosurfer.data.constants.UpdateConstants;

/**
 * The DAO layer supertype that includes functionality needed 
 * by most DAOs.
 *
 */
public class DAOObject implements UpdateConstants {
    
    /**
     * Default constructor.
     *
     */
    public DAOObject() {
    }
    
    /**
     * Converts a time value represented as milliseconds to
     * a Timestamp object that can be used with the JDBC API.
     * 
     * @param time Time as the number of milliseconds since 1970.
     * @return The corresponding Timestamp object.
     */
    public static Timestamp toSQLTime(long time) {

        Timestamp datetime = new Timestamp(time);
        return datetime;

    }
    
    /**
     * Converts a time value represented as milliseconds to
     * a Timestamp object that can be used with the JDBC API.
     * 
     * @param time Time as the number of milliseconds since 1970.
     * @return The corresponding Timestamp object.
     */
    public static Timestamp toSQLTime(Long time) {        
        return toSQLTime(time.longValue());
    }
    
    /**
     * Converts 0, 1 to false, true respectively.
     * 
     * @param num 0 or 1.
     * @return The corresponding boolean value.
     */
    public static boolean toBoolean(int num) {
        return (num == 0 ? false : true);
    }
    
    /**
     * Converts false, true to 0, 1 respectively.
     * 
     * @param b The boolean value.
     * @return The corresponding integer value.
     */
    public static int toInt(boolean b) {
        return (b ? 1 : 0);
    }

}